package com.xd.core.api.consumer;

import com.xd.core.api.dto.SignContractDto;
import com.xd.core.api.entity.RepaymentOrderInfo;
import com.xd.core.business.mapper.CertificationMapper;
import com.xd.core.business.mapper.CreditMapper;
import com.xd.core.business.mapper.OutInfoMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.Date;

@Slf4j
@Component
@RabbitListener(queues = "certification.queue")
public class CertificationConsumerController {
    @Autowired
    private OutInfoMapper outInfoMapper;
    @Autowired
    private CreditMapper creditMapper;
    @Autowired
    private CertificationMapper certificationMapper;
    //代扣申请失败
    @RabbitHandler
    public void SignPayFail(SignContractDto signContractDto) {
        //回滚数据
        outInfoMapper.deleteById(signContractDto.getOutId());
        certificationMapper.deleteById(signContractDto.getCertificationId());
        creditMapper.updateCreditAmountRest(signContractDto.getLoanAmount().multiply(BigDecimal.valueOf(-1)), signContractDto.getCreditId());
    }
}
